/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

import com.collabarative1.connectionUtils.ConnectionFactory;
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.Statement;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 *
 * @author Shravani
 */
@WebServlet(name = "FacultyRegistrationServlet", urlPatterns = {"/FacultyRegistrationServlet"})
public class FacultyRegistrationServlet extends HttpServlet {

    /**
     * Processes requests for both HTTP
     * <code>GET</code> and
     * <code>POST</code> methods.
     *
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    protected void processRequest(HttpServletRequest req, HttpServletResponse res)
            throws ServletException, IOException {
                int i=0;
        ConnectionFactory c=new ConnectionFactory();
res.setContentType("text/html");         
String Firstname="f"+req.getParameter("First name");
//Statement st=null;
  		
String lastname	=req.getParameter("last name");
 String dob=req.getParameter("Date of Birth");
 String Gender=req.getParameter("Gender");
 char ch=Gender.charAt(0);
String Address=req.getParameter("Address");
String  subject=req.getParameter("Subject");
String  exp1=req.getParameter("exp");
int exp=Integer.parseInt(exp1);
String Phonenumber1=req.getParameter("Phone number");

long Phonenumber=Long.parseLong(Phonenumber1);
String mail=req.getParameter("E-Mail id");
String password=req.getParameter("password");
//	Connection con=ConnectionFactory.getConnection();

	
//	String sql="insert into UserDB values(?,?,?,?,?,?,?,?);";

//		st=con.prepareStatement(sql);
//		st.setString(1, Firstname);
//		st.setString(2,lastname);
//		st.setString(3, dob);
//		st.setString(4,Gender );
//		st.setString(5, Address);
//		st.setString(6, Course);
//		st.setInt(7, Phonenumber);
//		st.setString(8, mail);
//		
//	
try{
    Connection con=c.getConnection();//DriverManager.getConnection("jdbc:Odbc:oradsn","system","system");
Statement st=con.createStatement();
  
	
	String sql="insert into faculty values('"+Firstname+"','"+lastname+"','"+dob+"','"+ch+"','"+Address+"','"+subject+"',"+exp+","+Phonenumber+",'"+mail+"','"+password+"')";
	//st=con.createStatement();
	//int i=0;
	i=st.executeUpdate(sql);
	st.close();
	con.close();
	} catch (Exception e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}
	RequestDispatcher rd=req.getRequestDispatcher("/index.jsp");//null;   //req.getRequestDispatcher("/Stuent");
boolean b;
	
	if(i==1)
	{
		b=true;
	req.setAttribute("status", b);
	req.setAttribute("uname", Firstname);
	
	}
	
	else
	{
	 b=false;
	req.setAttribute("status", b);
	}
	 rd.forward(req,res)	;
	
	}

    // <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
    /**
     * Handles the HTTP
     * <code>GET</code> method.
     *
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        processRequest(request, response);
    }

    /**
     * Handles the HTTP
     * <code>POST</code> method.
     *
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        processRequest(request, response);
    }

    /**
     * Returns a short description of the servlet.
     *
     * @return a String containing servlet description
     */
    @Override
    public String getServletInfo() {
        return "Short description";
    }// </editor-fold>
}
